import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default {
    state: {
        menuList: [],
        permissionList: [],
        //是否已经加载过路由了
        hasRoute: false,

        editableTabsValue: 'Index',
        editableTabs: [{
            title: '首页',
            name: 'Index',
        }]
    },
    mutations: {
        setMenuList(state,menuList){
            state.menuList = menuList
        },
        setPermissionList(state,permissionList){
            state.permissionList = permissionList
        },
        changeRouteStatus(state,hasRoute){
            state.hasRoute = hasRoute
            sessionStorage.setItem("hasRoute",hasRoute)
        },
        addTab(state,tab) {
            let idx = state.editableTabs.findIndex(item => item.name === tab.name)
            if(idx === -1){
                state.editableTabs.push({
                    title: tab.title,
                    name: tab.name
                });
            }
            state.editableTabsValue = tab.name;
        },
        resetState: (state) => {
            localStorage.clear()
            sessionStorage.clear()
            state.menuList = []
            state.permissionList = []
            state.hasRoute = false
            state.editableTabsValue = 'Index'
            state.editableTabs = [{
                title: '首页',
                name: 'Index',
            }]
        }
    },
    actions: {
    },
    modules: {
    }
}
